<?php

namespace app\traits;


trait Singleton
{
    /**
     * 单例
     * @var
     */
    private static $instance;

    /**
     * 获取实例
     * @return object
     */
    public static function getInstance(): object
    {
        !isset(self::$instance) and self::$instance = new self();
        self::$instance->initialization();
        return self::$instance;
    }

    protected function initialization(){}

    /**
     * 私有构造函数，防止实例被new所创建
     */
    private function __construct(){}

    /**
     * 私有克隆函数，防止被克隆
     * @return void
     */
    private function __clone(){}
}